<html>
<head><meta charset="utf-8"><title>Enum variant and associated constant with same name? · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Enum.20variant.20and.20associated.20constant.20with.20same.20name.3F.html">Enum variant and associated constant with same name?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209144957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Enum%20variant%20and%20associated%20constant%20with%20same%20name%3F/near/209144957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Enum.20variant.20and.20associated.20constant.20with.20same.20name.3F.html#209144957">(Sep 04 2020 at 22:01)</a>:</h4>
<p>I was surprised to find that this compiles:</p>
<div class="codehilite"><pre><span></span><code>pub enum Foo {
    A(i32),
}
impl Foo {
    pub const A: Self = Foo::A(0);
}
</code></pre></div>


<p>I'd thought that both went in the the value namespace, so they'd conflict with each other.  (Certainly <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=d1e7c140a60c78cc6ede62b677a74e5e">if you try to actually use the constant</a> it just gives the variant's voldemort fn.  Filed a bug that we should at least have a warning: <a href="https://github.com/rust-lang/rust/issues/76347">https://github.com/rust-lang/rust/issues/76347</a>)</p>
<p>What rule am I missing that makes this allowed?</p>



<a name="209144988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Enum%20variant%20and%20associated%20constant%20with%20same%20name%3F/near/209144988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Enum.20variant.20and.20associated.20constant.20with.20same.20name.3F.html#209144988">(Sep 04 2020 at 22:01)</a>:</h4>
<p>I ran in to this recently too</p>



<a name="209144995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Enum%20variant%20and%20associated%20constant%20with%20same%20name%3F/near/209144995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Enum.20variant.20and.20associated.20constant.20with.20same.20name.3F.html#209144995">(Sep 04 2020 at 22:01)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/75756#discussion_r479807425">https://github.com/rust-lang/rust/pull/75756#discussion_r479807425</a></p>



<a name="209145038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Enum%20variant%20and%20associated%20constant%20with%20same%20name%3F/near/209145038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Enum.20variant.20and.20associated.20constant.20with.20same.20name.3F.html#209145038">(Sep 04 2020 at 22:02)</a>:</h4>
<p>(might need to expand hidden comments)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>